﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class create_ways_to_play : System.Web.UI.Page
{

    ctpDataContext db = new ctpDataContext();
    int no;
    ct_s_profile cts ;
    ct_profile ct ;


    protected void Page_Load(object sender, EventArgs e)
    {

        no = int.Parse(Request["no"]);

        ctp_lib.check_login(this.Page,"create_ways_to_play.aspx?no="+no.ToString());

        cts = db.ct_s_profiles.Single(p => p.no == no&&p.valid==true);
        ct = db.ct_profiles.Single(p => p.no == cts.ct_no);


        if (!this.IsPostBack)
        {
            //cts = db.ct_s_profiles.Single(p => p.no == no);
            //ct = db.ct_profiles.Single(p => p.no == cts.ct_no);

            this.HyperLink2.Text = ct.title.Trim();
            this.HyperLink2.NavigateUrl = "city.aspx?no=" + ct.no.ToString();

            this.HyperLink9.Text = cts.title.Trim();
            this.HyperLink9.NavigateUrl = "city_s.aspx?no=" + cts.no.ToString();
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        ct_s_profile n_cts = new ct_s_profile();
        int newno = db.ct_s_profiles.Max(p => p.no) + 1;

        n_cts.no = newno;
        n_cts.add_time = DateTime.Now;
        n_cts.c_time = DateTime.Now;
        n_cts.create_user_no = (int)Session["userno"];
        n_cts.ct_no = ct.no;
        n_cts.type_no = 99;
        n_cts.title = this.TextBox1.Text;
        n_cts.valid = true;
        n_cts.ver = 0;
        n_cts.parent = no;
        n_cts.intro = this.TextBox2.Text;
        n_cts.main_pic_fn = "coming.gif";

        db.ct_s_profiles.InsertOnSubmit(n_cts);


        ct_s_intro i1 = new ct_s_intro();
        i1.ct_s_no = newno;
        i1.create_user_no = (int)Session["userno"];
        i1.intro = this.TextBox2.Text;
        i1.addtime = DateTime.Now;
        i1.ct_no = ct.no;

        db.ct_s_intros.InsertOnSubmit(i1);

        db.SubmitChanges();

        var r = from p in db.ct_s_intros
                where p.ct_s_no == newno && p.create_user_no == (int)Session["userno"]
                orderby p.addtime descending
                select p;
        int intro_no = r.First().no;

        DatabaseUtil my_util = new DatabaseUtil();
        int translaged_no = my_util.writeTranslatedTxt((int)DatabaseUtil.fromTables.s_profile_title, newno, this.TextBox1.Text, "en");
        translaged_no = my_util.writeTranslatedTxt((int)DatabaseUtil.fromTables.intro_intro, intro_no, this.TextBox2.Text, "en");

        translaged_no = my_util.writeTranslatedTxt((int)DatabaseUtil.fromTables.s_profile_intro, newno, this.TextBox2.Text, "en");
        

        Response.Redirect("city_s.aspx?no=" + no);

    }
}
